package com.pe.rentcar.ws;

import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;

public class RentcarEndpoint extends AbstractJDomPayloadEndpoint {

	private XPath marcaExpression;

	private XPath anoExpression;

	private XPath placaExpression;
	
	
	public RentcarEndpoint() throws JDOMException {

		Namespace namespace = Namespace.getNamespace("rentcar", "http://rentcar.com/rentcar/schemas");
		marcaExpression = XPath.newInstance("//rentcar:marca");
		marcaExpression.addNamespace(namespace);
		anoExpression = XPath.newInstance("//rentcar:ano");
		anoExpression.addNamespace(namespace);
		placaExpression = XPath.newInstance("//rentcar:placa");
		placaExpression.addNamespace(namespace);		
//		nameExpression = XPath.newInstance("concat(//rentcar:FirstName,' ',//rentcar:LastName)");
//		nameExpression.addNamespace(namespace);
	}
	
	protected Element invokeInternal(Element rentcarRequest) throws Exception {
		//SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String marca = marcaExpression.valueOf(rentcarRequest);
		String ano = anoExpression.valueOf(rentcarRequest);
		String placa = placaExpression.valueOf(rentcarRequest);

		System.out.println(marca + "  " + ano + placa);
		return null;
	}

}
